<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 17-4-11
 * Time: 22:46
 */

namespace frontend\widget;


use backend\models\Article;
use backend\models\ArticleCategory;
use yii\base\Widget;

class NavEndWidget extends Widget
{
    public function run()
    {
        $html = '<div class="bottomnav w1210 bc mt10">';
        //获取所有的帮助文章的分类
        $cates = $this->getHelpCate();
        foreach ($cates as $key =>$cate){
            //得到当前分类的文章
            $articles =$this->getHelpArticle($cate['id']);
            $link='';
            foreach ($articles as $article){
                $link.='<li><a href="">'.$article['name'].'</a></li>';
            }

            $key+=1;
           $html.='<div class="bnav'.$key.'"><h3><b></b> <em>'.$cate["name"].'</em></h3><ul>'.$link.'</ul></div>';

        }
        return $html.'</div>';


    }
    public function getHelpCate(){
        return ArticleCategory::find()->where(['is_help'=>1])->asArray()->all();
    }

    public function getHelpArticle($cate_id){
        return Article::find()->where(['article_category_id'=>$cate_id])->asArray()->all();
    }


}